// pages/mch/clerk/add.js
const App = getApp()
import Util from '../../../utils/util'

Page({
  data: {
    init: false,
    loading: false,


    pwd: "",
    hour: 1,
    name: "",
    mob: "",
    sms: false,
    flag: false,
    benefit: 0,

  },
  onLoad() {
    this.setData({
      init: true
    })
  },
  show() {
      wx.showToast({
        title: '该功能暂未开放',
        icon: 'none'
      })
  },
  doCheckInput(e) {
    let value = parseFloat(e.detail.value || '0')
    let min = parseFloat(e.target.dataset.min || '0')
    let max = parseFloat(e.target.dataset.max || '99999')
    if (value < min) {
      return min + ''
    }
    if (value > max) {
      return max + ''
    }
    return parseFloat(value.toFixed(2)) + ''
  },
  doSaveInfo() {

    if (!this.data.name) {
      Util.Notify.warn(`请填写店员名称`)
      return
    }
    if (!this.data.mob) {
      Util.Notify.warn(`请填写手机号码`)
      return
    }
    if (!this.data.idno) {
      Util.Notify.warn(`请填写身份证号`)
      return
    }

    this.setData({
      loading: true
    })
    App.doPost({
      uri: '/app/merchant/clerk/add',
      body: {
        pwd: this.data.pwd || this.data.mob.substring(8),
        hour: this.data.hour,
        name: this.data.name,
        mob: this.data.mob,
        idno: this.data.idno,
        sms: this.data.sms,
        benefit: this.data.flag ? parseInt(this.data.benefit * 10) : 0
      },
      fnSucc: () => {
        wx.pub("ReloadClerkList", {})
        Util.Toast.succ(`提交成功`)
        setTimeout(() => {
          wx.navigateBack({
            delta: 1
          })
        }, 1000);
      },
      fnFail: resp => {
        Util.Notify.error(`[${resp.stat.err}] ${resp.stat.msg}`)
      },
      fnComp: () => {
        this.setData({
          loading: false,
        })
      }
    })

  }
})